<template>
  <el-dialog :visible.sync="visible" :before-close="dialogClose">
    <el-table
      :data="tableData"
      border
      style="width: 100%"
      size="mini">
      <el-table-column
        prop="id"
        label="ID"
        min-width="20%">
      </el-table-column>
      <el-table-column
        prop="createdName"
        label="贡献人"
        min-width="10%">
      </el-table-column>
      <el-table-column
        prop="content"
        label="更新内容"
        min-width="15%">
      </el-table-column>
      <el-table-column
        prop="createdTime"
        label="创建时间"
        min-width="20%">
      </el-table-column>
      <el-table-column
        prop="stateName"
        label="状态"
        min-width="10%">
      </el-table-column>
      <el-table-column
        fixed="right"
        label="操作"
        min-width="20%">
        <template slot-scope="scope" >
          <el-button type="text" @click="detail(scope.row)" size="small">查看</el-button>
          <el-button type="text" @click="pass(scope.row)" v-if="scope.row.state == '1'" size="small">通过</el-button>
          <el-button type="text" @click="abort(scope.row)" v-if="scope.row.state == '1'" size="small">驳回</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      style="padding: 10px 10px 5px 10px;"
      :current-page="pageData.current"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :page-size="pageData.size"
      layout="total, prev, pager, next, jumper"
      :total="total"
    />
  </el-dialog>
</template>

<script>
  export default {
    name: 'MyFileApplyDialog',
    data: function() {
      return {
        tableData: [],
        pageData: {
          fileId: null,
          state: null,
          current: 1,
          size: 10,
        },
        total: 0,
      }
    },
    props: {
      fileId: String,
      fileInfo: Object,
      visible: Boolean,
    },
    watch: {
      fileId(val) {
        this.pageData.fileId = val;
        this.getApplyPage();
      }
    },
    created() {
      // this.getApplyPage();
    },
    methods: {
      getApplyPage() {
        this.$api.applyPage(this.pageData).then(res => {
          this.tableData = res.records;
        })
      },
      handleCurrentChange(val) {
        this.pageData.current = val;
        this.getApplyPage();
      },
      handleSizeChange(val) {
        this.pageData.size = val;
        this.getApplyPage();
      },
      dialogClose() {
        this.$emit("close");
      },
      pass(row) {
        this.$confirm('确定通过吗', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$api.passApply(row.id).then(res => {
            this.getApplyPage();
          })
        })
      },
      abort(row) {
        this.$confirm('确定通过吗', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$api.abortApply(row.id).then(res => {
            this.getApplyPage();
          })
        })
      },
      detail(row) {
        this.$router.push({name: "FileView", params: {fileInfo: {id: row.fileId, fileType: row.fileType}, applyId: row.id}});
      }
    }
  }
</script>

<style scoped>

</style>
